package com.sgb.kjwl.view.ui.adapter.transport;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.GoodsInfoEntity3;
import com.swgk.core.dialog.RoundCornerDialog;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class GoodsInfoOrderPriceAdapter3 extends BaseRecycleAdapter<GoodsInfoEntity3> {

    public GoodsInfoOrderPriceAdapter3(Context context, List<GoodsInfoEntity3> datas) {
        super(context, R.layout.item_goods_info_order3, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, GoodsInfoEntity3 goodsInfoEntity3) {
        holder.setBinding(BR.viewModel,goodsInfoEntity3);

        TextView tvPhone = holder.getItem().findViewById(R.id.driver_phone);
        tvPhone.setOnClickListener(view -> {

            showDialog(goodsInfoEntity3.getEndStation());
        });
    }

    public void showDialog(String phone) {
        View view = View.inflate(context, R.layout.dialog_two_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(context, 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失

        TextView tv_message = (TextView) view.findViewById(R.id.tv_message);
        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_logout_confirm = (TextView) view.findViewById(R.id.tv_logout_confirm);
        tv_title.setVisibility(View.VISIBLE);
        TextView tv_logout_cancel = (TextView) view.findViewById(R.id.tv_logout_cancel);
        tv_title.setText("确认呼叫");
        tv_message.setText(phone);

        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + "18911790321" + "\""));
                context.startActivity(intent);
                roundCornerDialog.dismiss();
            }
        });

        //取消
        tv_logout_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }
}
